package com.ryskoo.permission.managerrolerel.repository;

import com.ryskoo.framework.core.repository.BasicRedisImpl;
import com.ryskoo.framework.core.utils.RedisUtil;
import com.ryskoo.permission.managerrolerel.domain.ManagerRoleRelPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;
import java.util.List;

@Primary
@Repository
public class ManagerRoleRelRedisImpl extends BasicRedisImpl<ManagerRoleRelPO> implements IManagerRoleRelRepository {
	@Autowired
	private RedisUtil redisClient;

	@Autowired
	private IManagerRoleRelRepository managerRoleRelRepository;

	@PostConstruct
	public void init() {
		this.setRedisClient(redisClient);
		this.setDao(managerRoleRelRepository);
	}

	public ManagerRoleRelRedisImpl() {
		super("PERMISSION_MENU_");
	}

	@Override
	public List<String> getRoleUuidsByManagerId(String managerId) {
		return managerRoleRelRepository.getRoleUuidsByManagerId(managerId);
	}

	/**
	 * 根据管理员id删除其与所有角色的关联关系
	 *
	 * @param managerId
	 *            管理员id
	 */
	@Override
	public void deleteRelByManagerId(String managerId) {
		managerRoleRelRepository.deleteRelByManagerId(managerId);
	}

}
